package com.maple.common.widget.dialog

import android.content.Context
import android.os.Bundle
import android.view.WindowManager
import android.widget.Button
import android.widget.TextView
import com.blankj.utilcode.util.ScreenUtils
import com.maple.base.widget.dialog.BaseCenterDialog
import com.maple.common.R
import com.maple.utils.util.UIUtils

class CommonDialog(context: Context,
                   private val title: String = "温馨提示",
                   private val content: String = "",
                   private val cancel: String = "取消",
                   private val confirm: String = "确认",
                   private val listener: OnClickListener,
                   isCancelable:Boolean = false
): BaseCenterDialog(context,
    (ScreenUtils.getScreenWidth() * 0.42).toInt(),
    (ScreenUtils.getScreenHeight() * 0.48).toInt(),
    isCancelable = isCancelable){
    override fun getLayoutId(): Int = R.layout.dialog_common


    override fun initData(savedInstanceState: Bundle?) {
        findViewById<TextView>(R.id.tv_title).let {
            it.text = title
        }

        findViewById<TextView>(R.id.tv_content).let {
            it.text = content
        }
        findViewById<Button>(R.id.btn_cancel).let {
            it.text = cancel
            it.setOnClickListener {
                this.onCancel()
                listener.onCancelClick()
            }
        }
        findViewById<Button>(R.id.btn_confirm).let {
            it.text = confirm
            it.setOnClickListener {
                listener.onConfirmClick()
            }
        }
    }

    interface OnClickListener{
        fun onCancelClick(){}
        fun onConfirmClick(){}
    }
}